package com.bingxue.edu.teacher.controller;

import com.bingxue.edu.common.enums.OperateSourceEnum;
import com.bingxue.edu.framework.common.model.Response;
import com.bingxue.edu.management.education.model.req.LessonSignInReq;
import com.bingxue.edu.teacher.model.resp.TeacherClassLessonDetailResp;
import com.bingxue.edu.teacher.model.resp.TeacherClassLessonResp;
import com.bingxue.edu.teacher.service.TeacherLessonService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author panbo
 * @since 2024/11/7
 */
@Tag(name = "教师端小程序-排课模块")
@RestController
@RequestMapping("/t/lesson")
@RequiredArgsConstructor
public class TeacherClassLessonController {

    private final TeacherLessonService teacherLessonService;

    @Operation(summary = "查询班级课次列表")
    @GetMapping("/list/{classId}")
    public Response<List<TeacherClassLessonResp>> getClassLessons(@PathVariable String classId) {
        return Response.success(teacherLessonService.getClassLessonList(classId));
    }


    @Operation(summary = "查询课次详情")
    @GetMapping("/detail/{lessonId}")
    public Response<TeacherClassLessonDetailResp> getLessonDetailById(@PathVariable String lessonId) {
        return Response.success(teacherLessonService.getLessonDetailById(lessonId));
    }

    @Operation(summary = "点名")
    @PostMapping("/signIn")
    public Response<Void> signIn(@RequestBody @Validated LessonSignInReq req) {
        req.setOperateSource(OperateSourceEnum.TEACHER);
        teacherLessonService.signIn(req);
        return Response.success();
    }

    @Operation(summary = "撤销点名")
    @PostMapping("/unSignIn")
    public Response<Void> unSignIn(@RequestBody @Validated LessonSignInReq req) {
        req.setOperateSource(OperateSourceEnum.TEACHER);
        teacherLessonService.unSignIn(req);
        return Response.success();
    }
}
